#ifndef NULLSPATIALPARTITIONING_H_
#define NULLSPATIALPARTITIONING_H_

#include "SpatialPartitioning.h"
#include "hset.h"
#include "math/math.h"
#include "shapes.h"
#include "RigidBody.h"
#include <algorithm>

namespace physicsworks {

using math::vec3;

class NullSpatialPartitioning : public SpatialPartitioning {
private:
	typedef HSet<RigidBody*>::Type RigidBodyHSet;
	RigidBodyHSet rigidBodies; /**< Rigid bodies inside the spatial box */
	RigidBodyHSet outRigidBodies; /**< Rigid bodies outside the spatial box */
	
	vec3 min;
	vec3 max;
	
public:
	NullSpatialPartitioning(const vec3& a, const vec3& b);
	~NullSpatialPartitioning() {}
	
	list<pair<RigidBody*,RigidBody*> > getPotentialCollidingPairs();
	
	void add(RigidBody* b) {
		
		rigidBodies.insert(b);
	}
	
	void remove(RigidBody* b) {
		
		rigidBodies.erase(b);
	}
	
	void update();
	
private:

	/**
	 * Is the box inside the spatial box's boundaries?
	 */
	bool isInsideGridBoundaries(const AABox& box) const {
		return box.min.x >= min.x && box.min.y >= min.y && box.min.z >= min.z &&
		       box.max.x <= max.x && box.max.y <= max.y && box.max.z <= max.z;
	}
};

}

#endif /*NULLSPATIALPARTITIONING_H_*/
